package com.tyg.service.impl;

import com.tyg.entity.TbVenueOrder;
import com.tyg.mapper.TbVenueOrderMapper;
import com.tyg.pojo.VenueOrderInfo;
import com.tyg.service.TbVenueOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangjingnan
 * @since 2022-11-28
 */
@Service
public class TbVenueOrderServiceImpl extends ServiceImpl<TbVenueOrderMapper, TbVenueOrder> implements TbVenueOrderService {

    @Autowired
    TbVenueOrderMapper tbVenueOrderMapper;

    @Override
    public List<String> getUsedVenueInfo(TbVenueOrder tbVenueOrder) {
        List<TbVenueOrder> usedVenueInfo = tbVenueOrderMapper.getUsedVenueInfo(tbVenueOrder);
        List<String> times = new ArrayList();
        for (TbVenueOrder venueOrder : usedVenueInfo) {
            times.addAll(Arrays.asList(venueOrder.getVenueTime().split(",")));
        }
        return times;
    }

    @Override
    public void updateVenueOrderStatus(TbVenueOrder tbVenueOrder) {
        tbVenueOrderMapper.updateVenueOrderStatus(tbVenueOrder);
    }

    @Override
    public void insertNewOrder(TbVenueOrder tbVenueOrder) {
        tbVenueOrderMapper.insertNewOrder(tbVenueOrder);
    }

    @Override
    public List<VenueOrderInfo> getAllVenueOrder(TbVenueOrder tbVenueOrder) {
        List<VenueOrderInfo> tbVenueOrders = tbVenueOrderMapper.selectAllOrderInfo(tbVenueOrder);
        if (!ObjectUtils.isEmpty(tbVenueOrders)){
            for (VenueOrderInfo venueOrder : tbVenueOrders) {
                venueOrder.setCost(String.valueOf(venueOrder.getVenueTime().split(",").length * venueOrder.getVenuePrice()));
            }
            return tbVenueOrders;
        }else {
            return tbVenueOrders;
        }
    }


}
